import time
from pykeyboard import PyKeyboard
from selenium.webdriver.common.keys import Keys
from selenium import webdriver


class KeyTest():
     def login(self):
         driver = webdriver.Chrome()  # 实例化浏览器对象
         driver.get("http://192.168.121.128:8080/woniusales/")  # 发送访问WoniuSales的请求
         time.sleep(2)
         assert driver.find_element_by_xpath("//div[1]/div[1]/div[1]/div[1]").is_displayed()==True  # 断言是否进入蜗牛进销存登录页面

         driver.find_element_by_id("username").send_keys("admin")  # 输入用户名
         time.sleep(2)
         driver.find_element_by_id("username").send_keys(Keys.CONTROL,'a')   # 全选用户名
         time.sleep(2)
         driver.find_element_by_id("username").send_keys(Keys.CONTROL,'c')   # 复制
         time.sleep(2)
         driver.find_element_by_id("username").send_keys(Keys.DELETE)    # 清空用户名
         time.sleep(2)
         driver.find_element_by_id("password").send_keys(Keys.CONTROL,'v')  # 将用户名粘贴至密码域
         time.sleep(2)
         driver.find_element_by_id("password").send_keys(Keys.CONTROL,'a')   # 全选密码
         time.sleep(2)
         driver.find_element_by_id("password").send_keys(Keys.CONTROL,'c')    # 复制密码
         time.sleep(2)
         driver.find_element_by_id("verifycode").send_keys(Keys.CONTROL,'v')  # 将密码粘贴至验证码域
         time.sleep(2)
         k = PyKeyboard()
         k.press_key(k.enter_key)  # 回车点击登录
         time.sleep(2)



if __name__ == '__main__':
    ke = KeyTest()
    ke.login()